home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 January / macformat-020.iso / Shareware City / Developers / MungeImage Source 1.2.0 / DART Interfaces / DartIntf.h next >
Encoding:
C/C++ Source or Header  |  1994-08-07  |  6.1 KB  |  175 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        DartIntf.h
  3.  
  4.     Written by:    Ken McLeod
  5.  
  6.     Copyright:    © 1987-1994 by Apple Computer, Inc.
  7.                 All rights reserved.
  8.  
  9.     Version:    1.5.3
  10.     Created:    Wednesday, August 3, 1994 16:00
  11.  
  12. */
  13.  
  14. #ifndef __DARTINTF__
  15. #define __DARTINTF__
  16.  
  17. /*----------------------------------------------------------------------
  18. /*----------------------------------------------------------------------
  19.  
  20. Some notes on reading a DART™ image file:
  21.  
  22. DART™ is a program written by David Mutter and Ken McLeod of Apple
  23. Computer, Inc., for internal use in archiving and duplicating 3.5" floppy
  24. disks. Because of its utility in distributing compressed disk images on
  25. the Macintosh, DART™ is used in a number of Apple support products even
  26. though DART™ is not an official Apple product and is not supported as such.
  27.  
  28. The format of a DART™ file is provided here for READ-ONLY use.
  29. No guarantees are expressed or implied. Use at your own risk.
  30.  
  31.                            *  *  *  *  *
  32. File Header
  33. -----------
  34. The first word in the data fork of a DART™ file contains a compression
  35. identifier in the high byte (what type of compression is used), and a
  36. disk identifier in the low byte (what sort of disk this image contains).
  37. The second word contains the size of the source disk (e.g. 800=800K).
  38.  
  39. From this info, you can decide whether to interpret the file header as
  40. a structure of type HDSrcInfoRec (for 1440K disks) or SrcInfoRec (for
  41. everything smaller than 1440K.) The difference is in the size of the
  42. block lengths array, bLength.
  43.  
  44.  
  45. How DART™ creates a disk image
  46. ------------------------------
  47. DART™ reads data from a 3.5" disk in blocks of 20480 bytes, starting with
  48. sector 0 and continuing sequentially to the end of the disk. Each block
  49. is read into a buffer capable of holding 20960 bytes. The remaining 480
  50. bytes at the end of the buffer are filled with tag data (or zeroed, if
  51. tags are not supported.) This 20960-byte buffer is then compressed and
  52. written to the end of the image file. Finally, the appropriate element of
  53. the block lengths array is updated with the compressed block length.
  54.  
  55.  
  56. Important note about compressed block lengths
  57. ---------------------------------------------
  58. Block lengths are always expressed in bytes, with the following two
  59. exceptions:
  60.  
  61.   1) If the compression identifier is kRLECompress, the length of a
  62.   compressed block is expressed in 16-bit words (or 2-byte units).
  63.   Multiply by 2 to obtain the block size in bytes.
  64.   
  65.   2) If the block length is -1, then the block isn't compressed and
  66.   is assumed to be 20960 bytes.
  67.  
  68.  
  69. How to read a DART™ image file
  70. ------------------------------
  71. The basic procedure is to position the file mark at the end of the file
  72. header (which will either be sizeof(SrcInfoRec) or sizeof(HDSrcInfoRec)
  73. bytes), and read bLength[n] bytes from the file into a buffer. You then
  74. stream this compressed block through a decompression routine (either
  75. RLEExpandBlock() or LZHExpandBlock(), depending on the file's compression
  76. identifier) into a buffer capable of holding 20960 bytes. Remember that
  77. the first 20480 bytes are data, while the remaining 480 bytes are tags.
  78. Write out the data to disk, increment n, and repeat until bLength[n]==0
  79. or you reach the end of the file.
  80.  
  81. Checksums
  82. ---------
  83. DART™ uses the same checksum algorithm as Disk Copy (another Apple disk
  84. utility) to verify the integrity of the disk data. The 32-bit checksums
  85. for data and tags are stored separately in the resource fork of the image
  86. file, rather than as part of the file header. The tag checksum is stored
  87. in resource 'CKSM' ID=1, and the data checksum is stored in 'CKSM' ID=2.
  88.  
  89.  
  90. /*----------------------------------------------------------------------
  91. /*----------------------------------------------------------------------
  92.     disk identifiers
  93. /*----------------------------------------------------------------------*/
  94.  
  95. #define kMacDisk        1
  96. #define    kLisaDisk        2
  97. #define    kAppleIIDisk    3
  98.         
  99. #define    kMacHiDDisk        16
  100. #define    kMSDOSLowDDisk    17
  101. #define    kMSDOSHiDDisk    18
  102.  
  103. /*----------------------------------------------------------------------
  104.     file types
  105. /*----------------------------------------------------------------------*/
  106.  
  107. #define    kDartCreator    'DART'
  108. #define    kOldFileType    'DMdf'
  109. #define    kDartPrefsType    'DMd0'
  110. #define    kMac400KType    'DMd1'
  111. #define    kLisa400KType    'DMd2'
  112. #define    kMac800KType    'DMd3'
  113. #define    kApple800KType    'DMd4'
  114. #define    kMSDOS720KType    'DMd5'
  115. #define    kMac1440KType    'DMd6'
  116. #define    kMSDOS1440KType    'DMd7'
  117. #define    kDiskCopyType    'dImg'
  118.  
  119. /*----------------------------------------------------------------------
  120.     compression identifiers
  121. /*----------------------------------------------------------------------*/
  122.  
  123. #define    kRLECompress    0        /* "fast" algorithm */
  124. #define    kLZHCompress    1        /* "best" algorithm */
  125. #define    kNoCompress        2        /* not compressed */
  126.  
  127. /*----------------------------------------------------------------------
  128.     data structures
  129. /*----------------------------------------------------------------------*/
  130.  
  131. typedef unsigned char uchar;
  132. typedef unsigned short ushort;
  133. typedef unsigned long ulong;
  134.  
  135. typedef struct SrcInfoRec
  136. {
  137.     uchar    srcCmp;            /* compression identifier */
  138.     uchar    srcType;        /* disk type identifier (Lisa, Mac, etc.) */
  139.     short    srcSize;        /* size of source disk in Kb (e.g. 800=800K) */
  140.     short    bLength[40];    /* array of block lengths */
  141.     /* variable-length compressed disk data follows... */
  142. }    SrcInfoRec;
  143.  
  144. typedef struct HDSrcInfoRec
  145. {
  146.     uchar    srcCmp;            /* compression identifier */
  147.     uchar    srcType;        /* disk type identifier (Lisa, Mac, etc.) */
  148.     short    srcSize;        /* size of source disk in Kb (e.g. 800=800K) */
  149.     short    bLength[72];    /* array of block lengths */
  150.     /* variable-length compressed disk data follows... */
  151. }    HDSrcInfoRec;
  152.  
  153.  
  154. #define DDBLOCKSIZE    20960    /* size of an uncompressed block, in bytes */
  155.  
  156. typedef uchar DiskData[DDBLOCKSIZE], *DDPtr;
  157.  
  158.  
  159. /*----------------------------------------------------------------------
  160.     library functions
  161. /*----------------------------------------------------------------------*/
  162.  
  163. #ifdef __cplusplus
  164. extern "C" {
  165. #endif
  166.  
  167. pascal OSErr RLEExpandBlock(Ptr theBlock, DDPtr outputBuf, short blockLen);
  168. pascal OSErr LZHExpandBlock(Ptr theBlock, DDPtr outputBuf, short blockLen);
  169.  
  170. #ifdef __cplusplus
  171. }
  172. #endif
  173.  
  174.  
  175. #endif __DARTINTF__